{extend name='table'}

{block name="content"}
<div class="layui-tab layui-tab-card">
    <div class="layui-tab-content">
        {include file='/currency/index_search'}
        <table id="currency" data-url="{:sysuri()}" data-target-search="form.form-search"></table>
    </div>
</div>
{/block}

{block name="script"}
<script>
    $(function () {
        $('#currency').layTable({

            toolbar: '#toolbarDemo',
            even: true, height: 'full',
            sort: {field: 'create_at', type: 'desc'},
            cols: [[
                {checkbox: true, fixed: true},
                {field: 'currency_name', title: '{:lang("币制名称")}', align: 'center', minWidth: 120 },
                {field: 'currency_name_en', title: '{:lang("英文名称")}', align: 'center', minWidth: 120 },
                {field: 'abbreviation', title: '{:lang("代码")}', align: 'center', minWidth: 120 },
                {field: 'symbol', title: '{:lang("符号")}', align: 'center', minWidth: 120 },
                {field: 'exchange_rate', title: '{:lang("汇率")}', align: 'center', minWidth: 120},
                {field: 'is_default', title: '{:lang("默认币种")}', align: 'center', minWidth: 120, templet: d => ['{:lang("否")}','{:lang("是")}'][d.is_default] },
                {field: 'status', title: '{:lang("使用状态")}', align: 'center', minWidth: 110, templet: '#StatusSwitchTpl'},
                {field: 'desc', title: '{:lang("备注")}', align: 'center', minWidth: 120},
                {field: 'create_at', title: '{:lang("添加时间")}', align: 'center', width: 105, sort: true},
                {toolbar: '#toolbar', title: '{:lang("操作面板")}', align: 'center', width: 120, fixed: 'right'}
            ]]
        });
    });

    // 数据状态切换操作
    layui.form.on('switch(StatusSwitch)', function (obj) {
        var data = {id: obj.value, status: obj.elem.checked > 0 ? 1 : 0};
        $.form.load("{:url('state')}", data, 'post', function (ret) {
            if (ret.code < 1) $.msg.error(ret.info, 3, function () {
                $('#currency').trigger('reload');
            }); else {
                $('#currency').trigger('reload')
            }
            return false;
        }, false);
    });
</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <!--        {if auth("add")}-->
        <button data-modal='{:url("add")}' data-title="{:lang('添加')}" class='layui-btn layui-btn-sm '>{:lang('添 加')}</button>
        <!--        {/if}-->
        <!--        {if auth("remove")}-->
        <a data-confirm="{:lang('确定要删除吗')}" data-table-id="currency" data-action="{:url('remove')}" data-rule="id#{id}" class='layui-btn layui-btn-sm layui-btn-danger'>{:lang('批量删除')}</a>
        <!--        {/if}-->
    </div>
</script>
<script type="text/html" id="toolbar">
    {if auth("edit")}
    <a class="layui-btn layui-btn-xs" data-event-dbclick data-title="{:lang('编辑物料')}" data-modal='{:url("edit")}?id={{d.id}}'>{:lang('编 辑')}</a>
    {/if}
    {if auth("remove")}
    <a class="layui-btn layui-btn-xs layui-btn-danger" data-confirm="{:lang('确定要永久删除吗')}" data-action="{:url('remove')}" data-value="id#{{d.id}}">{:lang('删 除')}</a>
    {/if}
</script>

<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTpl">
    <!--{if auth("state")}-->
    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="{:lang('已激活')}|{:lang('已禁用')}" lay-filter="StatusSwitch" {{-d.status>0?'checked':''}}>
    <!--{else}-->
    {{-d.status ? '<b class="color-green">{:lang("已激活")}</b>' : '<b class="color-red">{:lang("已禁用")}</b>'}}
    <!--{/if}-->
</script>
{/block}
